//全局配置初始化
;(function(window){
    //ajax全局设置
    $.ajaxSetup({
        cache: false,//取消浏览器缓存
        complete:function(xhr,status){//session过期判断
            if(status=="parsererror"){//json解析失败的错误
                window.open("login", target="_top");
                //layer.msg("parsererror");
            } else if(xhr.status==504){
                layer.alert("请求超时，请稍后再试！");
            } else if(status=="error"){
                layer.alert("请求异常，请稍后再试！");
            }
        }
    });
	//layui
    layer.config({
        extend: 'extend/layer.ext.js'
    });

})(window);
//工具初始化
;(function(win){
	var pwin = win.parent;
    var $p = win.Public = {};
    $p._version = "v1.0.0";
    //tab 操作
    $p._tab = win.Tab||pwin.Tab || {};
    $p._message = win.Message||pwin.Message || {};
    $p._tab.bindCtrl = function(){
    	var _this = this;
        if(this.M && pwin!=win){
            $("#tab_refresh_btn").on("click",function(){
                _this.M.reload(_this.M.getSelectedTabItemID());
            });
            $("#tab_close_others_btn").on("click",function(){
                _this.M.removeOther(_this.M.getSelectedTabItemID());
            });
            $("#tab_close_all_btn").on("click",function(){
                _this.M.removeAll(_this.M.getSelectedTabItemID());
            });
        }
	};
    $p._tab.bindCtrl();


    //grid 表格
    $p._grid = {
        setSize:function($grid) {
            var gw = $grid.closest(".ui-jqgrid").parent().innerWidth();
            $grid.jqGrid("setGridWidth",gw - 5);
        },
        autoSize:function($grid){
            var _this = this ;
            _this.setSize($grid);
            $(window).resize(function(){
                _this.setSize($grid);
            });
        },
        /**在单元格加上这个代码就可以合并值一样的 categoryManagerName 列名
         cellattr: function(rowId, tv, rawObject, cm, rdata) {
                //合并单元格
                return 'id=\'categoryManagerName' + rowId + "\'";
            }
         **/
        merger:function(gridName, CellName,CellName2) { //CellName2参照列
            //得到显示到界面的id集合
            var mya = $("#" + gridName + "").getDataIDs();
            //当前显示多少条
            var length = mya.length;
            for (var i = 0; i < length; i++) {
                //从上到下获取一条信息
                var before = $("#" + gridName + "").jqGrid('getRowData', mya[i]);
                //定义合并行数
                var rowSpanTaxCount = 1;
                for (j = i + 1; j <= length; j++) {
                    //和上边的信息对比 如果值一样就合并行数+1 然后设置rowspan 让当前单元格隐藏
                    var end = $("#" + gridName + "").jqGrid('getRowData', mya[j]);
                    if (before[CellName2] == end[CellName2]) {
                        rowSpanTaxCount++;
                        $("#" + gridName + "").setCell(mya[j], CellName, '', { display: 'none' });
                    } else {
                        rowSpanTaxCount = 1;
                        break;
                    }
                    $("#" + CellName + "" + mya[i] + "").attr("rowspan", rowSpanTaxCount);
                }
            }
        }
    };
	//上传下载
    $p._upload = {

	};
    //窗口操作
    $p._win =  {
        gridBigHeight:function(){
            return $(win).height()-$(".grid-wrapper").offset().top-200;
        },
		gridBigOpenHeight:function(){
            return $(win).height()*0.8+"px";
        },gridBigOpenWidth:function(){
            return $(win).width()*0.8+"px";
        }
    }

	win.Public = $p;
    win.pwin = pwin;
})(window);




